package com.android.baselibrary.tool;

import androidx.fragment.app.FragmentActivity;
import com.android.baselibrary.dialog.BaseDialogFragment;
import com.android.baselibrary.dialog.LoadingDialogFragment;
import java.util.HashMap;
import java.util.Map;

public class CommLoading {

    static BaseDialogFragment mDialog;

    public static void showLoading(FragmentActivity mContext, String... text) {
        try {
            Map<String, Object> param = new HashMap<>();
            if (text.length > 0)
                param.put("text", text[0]);
            mDialog = LoadingDialogFragment.showDialog(mContext, param);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    public static void showLoading(Fragment mContext, String... text) {
//        try {
//            Map<String, Object> param = new HashMap<>();
//            if (text.length > 0)
//                param.put("text", text[0]);
//            mDialog = LoadingDialogFragment.showDialog(mContext.getChildFragmentManager(), param);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    //隐藏弹窗
    public static void dismissLoading() {
        try {
            if (mDialog != null) {
                mDialog.dismissWithAnim();
                mDialog = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //隐藏弹窗
    public static void dismissWithoutAnim() {
        try {
            if (mDialog != null) {
                mDialog.dismiss();
                mDialog = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
